package Thread;

/**
 * @projectName: Thread-20250806
 * @package: Thread
 * @className: Homework3
 * @author: Tongxinxin
 * @description: 有三个线程，分别只能打印A，B和C
 * 要求按顺序打印ABC，打印10次
 * 输出示例：
 * ABC
 * ABC
 * ABC
 * ABC
 * ABC
 * @date: 2025/8/9 20:51
 * @version: 1.0
 */
public class Homework3 {
    public static void main(String[] args) throws InterruptedException {
        Object locker=new Object();
        for (int i = 0; i < 10; i++) {
            Thread t1 = new Thread(() -> {
                synchronized (locker) {
                    System.out.print("A");
                }
            });
            Thread t2 = new Thread(() -> {
                synchronized (locker) {
                    System.out.print("B");
                }
            });
            Thread t3 = new Thread(() -> {
                synchronized (locker) {
                    System.out.print("C");
                }
            });
            t1.start();
            t2.start();
            t3.start();
            t1.join();
            t2.join();
            t3.join();
            System.out.print("\n");
        }

    }
}
